<%--
  Created by IntelliJ IDEA.
  User: Rui
  Date: 2018/9/8
  Time: 9:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html style="background-color: #fff;">
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
    <style>
        button,.common-form .layui-form-item .layui-input-inline{
            width: 100%;
        }
        .layui-form{
            margin: 15px;
        }
    </style>
</head>
<body>

<div class="layui-form common-form" lay-filter="layuiadmin-form-systemTypeGroup" id="layuiadmin-form-systemTypeGroup"  >
    <div id="auth">
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <button type="button" attr-type="0" class=" oauth layui-btn layui-btn-lg layui-btn-radius layui-btn-normal" >支付宝认证</button>

            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <c:if test="${isSubmit}">
                    <c:if test="${signRecord.status==10}">
                        <button type="button"  class="  layui-btn layui-btn-lg layui-btn-radius  layui-btn-warm">
                            小微商户入驻完成,去[
                            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-href="<%=basePath%>manager/merchant/applicationConfig/index/${signRecord.merchantNo}.html" >应用配置</a>
                            ]
                        </button>
                    </c:if>
                    <c:if test="${signRecord.status==5}">
                        <button type="button"  class="  layui-btn layui-btn-lg layui-btn-radius  layui-btn-warm" onclick="microGetUpGradeState('${signRecord.mchId}')">
                            小微商户入驻完成,去商户升级
                        </button>
                    </c:if>
                    <c:if test="${signRecord.status!=5 && signRecord.status!=10 }">
                        <button type="button" onclick="microGetState('${signRecord.applymentId}')" class="  layui-btn layui-btn-lg layui-btn-radius  layui-btn-warm"style="width: 160px">
                            【<c:if test="${signRecord.status==0}">审核中</c:if><c:if test="${signRecord.status==4}">待签约</c:if>】
                        </button>
                    </c:if>

                </c:if>
                <c:if test="${!isSubmit}">
                    <button type="button" attr-type="1" class=" oauth  layui-btn layui-btn-lg layui-btn-radius  layui-btn-warm" >微信认证</button>
                </c:if>

            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-inline">
                <button type="button" attr-type="2" class=" oauth layui-btn layui-btn-lg layui-btn-radius " >银联认证</button>

            </div>
        </div>
    </div>
    <div id="info">

    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-submit" id="LAY-submit" value="确认">
    </div>
</div>

<%@include file="../../../../resources/inc/footer.jsp" %>
<script>
    var id=${id};
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload ;
        $('.oauth').click(function () {
            layer.msg('资料提交中...', {
                icon: 16
                ,shade: 0.01
            });
            $.ajax({
                url:"<%=basePath%>manager/merchant/oauth/"+id+"/"+$(this).attr('attr-type')+"/oauth.html",
                type:"POST",
                dataType:"JSON",
                success:function (data) {
                    layer.closeAll('loading');
                    if(data.success){
                        layer.msg("微信提交审核成功,5分钟后查询状态");
                        setTimeout(function () {
                             window.location.reload();
                        },2000);
                    }else{
                        layer.msg(data.message, {icon: 5});
                    }
                }
            });
        })
    })
    //商户状态
    function microGetState(businessCode) {
        layer.msg('状态查询中...', {
            icon: 16
            ,shade: 0.01
        });
        $.ajax({
            url:"<%=basePath%>manager/merchant/oauth/"+businessCode+"/microGetState.html",
            type:"POST",
            dataType:"JSON",
            success:function (data) {
                layer.closeAll('loading');
                if(data.success){
                    layer.msg("将此二维码发送给法人进行授权");
                    $("#auth").hide();
                    var $img=$("<img src='"+data.data+"'> ")
                    $("#info").html($img).css("text-align","center")
                    $("#info").show();
                    setTimeout(function () {
                        //window.location.reload();
                    },2000);

                }else{
                    layer.msg(data.message, {icon: 5});
                }
            }
        });
    }
    function microGetUpGradeState(mchId) {
        layer.msg('状态查询中...', {
            icon: 16
            ,shade: 0.01
        });
        $.ajax({
            url:"<%=basePath%>manager/merchant/oauth/"+mchId+"/microGetUpGradeState.html",
            type:"POST",
            dataType:"JSON",
            success:function (data) {
                layer.closeAll('loading');
                if(data.success){
                    layer.msg("将此二维码发送给法人进行授权");
                    $("#auth").hide();
                    var $img=$("<img src='"+data.data+"'> ")
                    $("#info").html($img).css("text-align","center")
                    $("#info").show();
                    setTimeout(function () {
                        //window.location.reload();
                    },2000);

                }else{
                    layer.msg(data.message, {icon: 5});
                    setTimeout(function () {
                        window.location.reload();
                    },2000);
                }
            }
        });
    }

</script>
</body>
</html>
